<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>美业红</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <link href="/public/css/main.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4;">
        <div class="navigation">
            <div class='navlogo'>
            <a href='/'><img class='_navlogo' src="/public/images/logo.png"></a>
            </div>
            <div class='navson'>
                <ul class='fr'>
                <li><a href='/' class='anchor'><b>主页</b></a></li>
                <li><a href="/home/store" class='anchor'><b>店铺</b></a></li>
                <li><a href="/home/barber" class='anchor'><b>成员</b></a></li>
                <li><a href="/home/action" class='anchor'><b>活动</b></a></li>
                <li><a href="/home/order" class='anchor'><b>订单</b></a></li>
                <li><a href="/home/coupon" class='anchor'><b>优惠券</b></a></li>
                <li><a href="/home/goods" class='anchor'><b>商品</b></a></li>
                </ul>
           </div>
            <?php if($_SESSION['id']>0){?>
            <div style="float:right;padding-right:10%">你好:<span id='login_name'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/repassword'>修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/logout'>退出</a></div>
            <?php }?>
        </div>
        <div style='margin-top:80px;width:100%'>
            <img class='_navlogo' src="/public/images/contentlogo.png" style='width:100%;height:100px'>
        </div>
        <div class='container'>
            <div class='_main'>
            <div class='_line'></div> 
<div>
    <div class='map_div'>
        <form  action='/home/store/create' method="post" id='form'>
            <div class='form-group row'>
             <?php if($edit==1){?>
             <label for="exampleInputName2" >指定负责人：</label><select style="width:15rem" name='principal'>
                 <option value='0'>超级管理员</option>
                 <?php foreach($barbers as $v){?>
                 <option value="<?php echo $v['id'];?>" <?php if($v['user_id']==$store['user_id']){echo "selected='selected'";}?>><?php echo $v['name'];?></option>
                 <?php }?>
             </select><span class='_prompt'>此处可以选择发型师，默认负责人为超级管理员负责该店。</span>
             <?php }?>
             </div>
             <div class='form-group row'>
                <label for="exampleInputName2" >店铺Logo:</label>
                <?php if($store['id']>0){?>
                <input type='hidden'  class="form-control" name='banner_logo' id='banner_logo' value="<?php echo $store['logo'];?>">
                <img src="<?php echo $store['logo'];?>" class="form-control" style="width:53rem;height: 17.6rem;border:1px;border-color: black" id="_banner_"alt=''/>
                <?php }else{?>
                <input type='hidden'  class="form-control" name='banner_logo' id='banner_logo' value='/public/images/logo.jpeg'>
                <img src="/public/images/logo.jpeg" class="form-control" style="width:53rem;height: 17.6rem;border:1px;border-color: black" id="_banner_"/>
                <?php }?>
                <iframe src="/home/store/img" frameborder="no" border="0" scrolling='no' style="width:25rem;height: 4rem;padding-top: 1rem" ></iframe>
             </div>
             <div class='form-group row'>
                <label for="exampleInputName2" >微信公众号永久二维码:</label>
             
                <input type='hidden'  class="form-control" name='code_img' id='code_img' value="<?php echo $store['code'];?>">
                <img src="<?php echo $store['code'];?>" class="form-control" style="width:20rem;height: 20rem;border:1px;border-color: black;"id="code" alt="请 添加 二维码"title='二维码' />
                <iframe src="/home/store/code" frameborder="no" border="0" scrolling='no' style="width:25rem;height: 4rem;padding-top: 1rem"  ></iframe>
             </div>
            <input type='hidden' name='id' value='<?php echo $store['id'];?>'>
            <div class='form-group row'>
                <label for="exampleInputName2">店铺名称:</label>
                <input type="text" class="form-control" name='name' placeholder="" value="<?php echo $store['name'];?>"/>
            </div>

            <div class='form-group row'>
                <label for="exampleInputName2">负责人（联系人）:</label>
                <input type="text" class="form-control" name='person_charge' placeholder="" value="<?php echo $store['person_charge'];?>"/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">联系电话:</label>
                <input type="text" class="form-control" name='tel' placeholder="" value="<?php echo $store['tel'];?>"/>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">所在地:</label>
                省：<select name="province" id="province" style='width:10rem' onchange="codeAddress(true);">
                    <option value='0'>--请选择--</option>
                    <?php foreach($provinces as $k=>$v){ if($store['province'] == $v['provinceid']){ echo '<option id="province_'.$v['provinceid'].'" value="'.$v['provinceid'].'" selected="selected">'.$v['province'].'</option>'; }else{ echo '<option id="province_'.$v['provinceid'].'" value="'.$v['provinceid'].'">'.$v['province'].'</option>'; } }?>
                </select>&nbsp;&nbsp;&nbsp;
                市：<select name="city" id="city" style='width:10rem' onchange="codeAddress(true);">
                    <option value='0'>--请选择--</option>
                    <?php foreach($cities as $k=>$v){ if($store['city'] == $v['cityid']){ echo '<option id="city_'.$v['cityid'].'" value="'.$v['cityid'].'" selected="selected">'.$v['city'].'</option>'; }else{ echo '<option id="city_'.$v['cityid'].'" value="'.$v['cityid'].'">'.$v['city'].'</option>'; } }?>
                </select>&nbsp;&nbsp;&nbsp;
                区：<select name="area" id="area" style='width:10rem' onchange="codeAddress(true);">
                    <option value='0'>--请选择--</option>
                    <?php foreach($areas as $k=>$v){ if($store['area'] == $v['areaid']){ echo '<option id="area_'.$v['areaid'].'" value="'.$v['areaid'].'" selected="selected">'.$v['area'].'</option>'; }else{ echo '<option id="area_'.$v['areaid'].'" value="'.$v['areaid'].'">'.$v['area'].'</option>'; } }?>
                </select>
            </div>
            <div class='form-group row'>
                <label for="exampleInputName2">店铺地址:</label>
                <input onblur='codeAddress(false);' type="text" class="form-control" id='address' name='address' placeholder="" value="<?php echo $store['address'];?>"/>
                <span class='_prompt'>为保证用户正确找到店面地址，请保证地图标记点与您输入地址一致。</span>
            </div>
            <div class='form-group row'>
                <div id='map' style="width:100%; height:30rem"></div>
            </div>
            <div class="form-group login_sub">
                <input type="submit" class="btn btn-info maskLayer" name="submit" value="提交">
            </div>
                   <input type='hidden' id='latlng' name='latlng' value='<?php echo $pnum['latlng'];?>'>
        </form>
        <div>
            <div id='map'></div>
        </div>
    </div>
</div>
<script type='text/javascript'>
    $(document).ready(function () {
        $("#form").validate({
            rules: {
                name: {
                    required: true,
                },
                province:{
                    required: true,
                    number:true,
                },
                city:{
                    required: true,
                    number:true,
                },
                area:{
                    required: true,
                    number:true,
                },
                address: {
                    required: true,
                },
                person_charge: {
                    required: true,
                },
                tel: {
                    required: true,
                },
            },
            messages: {
                name: {
                    required: '请输入店铺名称',
                },
                province:{
                    required: "请选择省",
                    number:"请选择省",
                },
                city:{
                    required: "请选择市",
                    number:"请选择市",
                },
                area:{
                    required: "请选择区",
                    number:"请选择区",
                },
                address: {
                    required: '请输入店铺地址',
                },
                person_charge: {
                    required: '请输入联系人姓名',
                },
                tel: {
                    required: '请输入联系人电话',
                },
            }
        });

    });
</script>
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>
<script>
    var biaoshi = true;
var geocoder,map;marker = new qq.maps.Marker({
                    map: null,
                    position: null
                });
window.onload = function () {
    function init() {
        //定义map变量 调用 qq.maps.Map() 构造函数   获取地图显示容器
        map = new qq.maps.Map(document.getElementById("map"), {
            center: new qq.maps.LatLng(<?php if(strlen($store['latlng'])>1){echo $store['latlng'];}else{?>39.916527, 116.397128<?php }?>), // 地图的中心地理坐标。
            zoom: 10
        });
        qq.maps.event.addListener(map, 'click', function(event) {
            marker.setMap(null);
            marker=new qq.maps.Marker({
                    position:event.latLng, 
                    map:map
            });
            var lng = event.latLng.getLng();
            var lat = event.latLng.getLat();
            var lat = parseFloat(lat);
            var lng = parseFloat(lng);
            var latLng = new qq.maps.LatLng(lat, lng);
            //调用信息窗口
            var info = new qq.maps.InfoWindow({map: map});
            //调用获取位置方法
            geocoder.getAddress(latLng);
        });
        //var info = new qq.maps.InfoWindow({map: map});
        geocoder = new qq.maps.Geocoder({
            complete: function (result) {
                map.setCenter(result.detail.location);
                marker.setMap(null);
                marker = new qq.maps.Marker({
                    map: map,
                    draggable: true,
                    position: result.detail.location
                });
                if(biaoshi == true){
                    $('#address').val(result.detail.address);
                }
                $('#latlng').val(result.detail.location);
            }
        });
    }
    
    //调用初始化函数地图
    init();
    codeAddress();
    
    $('#province').change(function(){
        var province = $('#province').val();
        $.ajax({
            url:"/home/Store/getcities?id="+province,
            async:true,
            success:function(data){
                if(data == "false"){
                    return;
                }
                data = eval('(' + data + ')');
                var str = "<option value='0'>--请选择--</option>";
                $(data).each(function(i){
                    str += "<option id='city_"+this.cityid+"' value='"+this.cityid+"'>"+this.city+"</option>";
                });
                $('#city').html(str);
                $('#area').html("<option value='0'>--请选择--</option>");
            }
        });
    });
    $('#city').change(function(){
        var city = $('#city').val();
        $.ajax({
            url:"/home/Store/getareas?id="+city,
            async:true,
            success:function(data){
                if(data == "false"){
                    return;
                }
                data = eval('(' + data + ')');
                var str = "<option value='0'>--请选择--</option>";
                $(data).each(function(i){
                    str += "<option id='area_"+this.areaid+"' value='"+this.areaid+"'>"+this.area+"</option>";
                });
                $('#area').html(str);
            }
        });
    });
    
}
function codeAddress(bool) {
    var province = $("#province").val();
    if(province==0){
        return ;
    }
    privonce = $('#province_'+province).html();
    var city = $("#city").val();
    city = $('#city_'+city).html();
    if(city=='市辖区' || city=='县'){
        city = '';
    }
    var area = $("#area").val();
    area = $('#area_'+area).html();
    var str = privonce+','+city+','+area;
    var address = document.getElementById("address").value;
    if(bool == false){
        biaoshi = false;
        address = str+address;
    }else{
        address = str;
    }
    //通过getLocation();方法获取位置信息值
    geocoder.getLocation(address);
}

</script>
<script type="text/javascript">
 $(document).ready(function(){
        if( $("#code").attr('src') =='' ){
               $("#code").css("padding-top","10rem");
               $("#code").css("padding-left","5rem");
        }
 })
</script>

</div>
</div>
<div class='_line'></div>
<div class="newfooter">
    ©2015-2017 All Rights Reserved ( 京ICP备15010043号 ) 
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
     background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
</body>
<script type="text/javascript" src='/public/js/top.js'></script>
</html>